<?php

class venta_model extends CI_Model {

    public function construct() {
        parent::__construct();
    }

     public function detallepedidosgetall($params) {
        $sql = "call usp_verdetallepedido(?)";
        $query = $this->db->query($sql, $params);     
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
        
    }
     public function anularpedido($params) {
        $sql = "call usp_anularpedido(?,?,?)";
        $this->db->query($sql, $params);        
    }
     public function pedidoshoygetall($params) {
        $sql = "call usp_pedidoshoygetall(?)";
        $query = $this->db->query($sql, $params);     
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
        
    }
    
    public function pedidoinsert($params) {
        $sql = "call usp_pedidoinsert(?,?,?,?,?)";
        $query = $this->db->query($sql, $params);     
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
        
    }
    
    public function detallepedidoinsert($params) {
        $sql = "call usp_detallepedidoinsert(?,?,?,?,?,?,?,?)";
        $this->db->query($sql, $params);        
    }
    
public function I_Venta($params) {
        $sql = "call sp_IComprobanteVenta(?,?,?,?,?,?,?,?,?)";
        $this->db->query($sql, $params);
    }
    
    public function I_detVenta($params) {
        $sql = "call sp_IDetVenta(?,?,?,?,?,?,?)";
        $this->db->query($sql, $params);
    }
    
    
        public function ultimoCodigoSucursal($params) {
       
        $sql = "call sp_obtenerUltimoIDSucursal(?,?)";
        
        return  $this->db->query($sql, $params);
    }
    
     public function ultimoCodigoVenta($params) {
        $sql = "call sp_obtenerelultimocodigoSucursal(?,?,?,?)";
        return $this->db->query($sql, $params);
    }
    
       public function listarComprobanteRep($det,$vent) {
        $sql = "CALL sp_lisComprobImpresion($det,$vent)";
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
    }
    
     public function listarComprobanteFor($params) {
        $sql = "call sp_listarVentas(?,?)";
        $query = $this->db->query($sql,$params);
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $fila) :
                $data[] = $fila;
            endforeach;
        }else {
            $data = null;
        }
        return $data;
    }
    
    
}